package org.vectrics.mail;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.activation.DataHandler;
import javax.activation.FileDataSource;

import org.apache.log4j.Logger;
import org.vectrics.SystemException;
import org.vectrics.domain.Domain;

/**
 * @author mmoore
 */
public class MailMessage implements Serializable {
    public static int CONTENT_TEXT = 0;
    public static int CONTENT_HTML = 1;

    private transient final Logger log = Logger.getLogger(this.getClass());
	private String subject;
	private String body;
	private String fromAddress;
	private String fromName;
	private int contentType = CONTENT_TEXT;
	private List attachedFiles = new ArrayList();
	private Domain domain = null;
	/**
	 * 
	 */
	public MailMessage(Domain domain) {
		super();
		if (domain == null)
			throw new SystemException("Domain not specified");
		this.domain = domain;
	}
	
	public Domain getDomain() {
		return(this.domain);
	}
	/**
	 * @return Returns the body.
	 */
	public String getBody() {
		return body;
	}
	/**
	 * @param body The body to set.
	 */
	public void setBody(String body) {
		this.body = body;
	}
	/**
	 * @return Returns the subject.
	 */
	public String getSubject() {
		return subject;
	}
	/**
	 * @param subject The subject to set.
	 */
	public void setSubject(String subject) {
		this.subject = subject;
	}
	/**
	 * @return Returns the fromAddress.
	 */
	public String getFromAddress() {
		return fromAddress;
	}
	/**
	 * @param fromAddress The fromAddress to set.
	 */
	public void setFromAddress(String fromAddress) {
		this.fromAddress = fromAddress;
	}
	/**
	 * @return Returns the fromName.
	 */
	public String getFromName() {
		return fromName;
	}
	/**
	 * @param fromName The fromName to set.
	 */
	public void setFromName(String fromName) {
		this.fromName = fromName;
	}
	
	
    /**
     * @return Returns the contentType.
     */
    public int getContentType() {
        return contentType;
    }
    /**
     * @param contentType The contentType to set.
     */
    public void setContentType(int contentType) {
        this.contentType = contentType;
    }
    
    public void addAttachmentFile(String fileName) {
    	log.debug("Testing existence of file");
    	File file = new File(fileName);
    	if (file.isFile() == false) {
    		throw new SystemException("File sent as attachment does not exist");
    	}
    	this.attachedFiles.add(fileName);
    }

    
    
    /**
	 * @return Returns the attachedFiles.
	 */
	public List getAttachedFiles() {
		return attachedFiles;
	}


	/**
	 * @param attachedFiles The attachedFiles to set.
	 */
	public void setAttachedFiles(List attachedFiles) {
		this.attachedFiles = attachedFiles;
	}


}
